﻿using Guoc.BigMall.Infrastructure.Caching;
using Guoc.BigMall.Infrastructure.Log;
using Guoc.BigMall.Web.Services;
using Guoc.BigMall.WebService;
using Guoc.BigMall.WebService.Dto;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace Guoc.BigMall.Web.Controllers
{
    public class AuthController : Controller
    {
        ILogger _log;
        IAuthenticateService _authenticateService;
        ICacheManager _cache;

        public AuthController(ILogger log,  IAuthenticateService authenticateService,ICacheManager cache)
        {
            this._log = log;
            this._authenticateService = authenticateService;
            this._cache = cache;
        }
        [HttpPost]
        /// <summary>
        ///  账号登录： 手机号登录
        /// </summary>
        /// <param name="code"> code 值</param>
        /// <param name="state">自定义参数</param>
        /// <returns></returns>
        public ActionResult Login(LoginDto model)
        {

            var result = _authenticateService.Login(model);

            return new JsonNetResult(ResultModel.Ok(result));
        }

        [TokenAuthorize]
        public ActionResult Logout()
        {
            var token = Request.Headers["token"];
            _cache.Remove(token);
            return new JsonNetResult(ResultModel.Ok());
        }
    }
}